Skip to content

Conversation

@lambdalisue
Copy link
Owner

@lambdalisue lambdalisue commented Oct 18, 2025

Summary

  • Use buffer numbers instead of buffer names for cleanup autocmd to prevent issues with special characters
  • Replace nvim_buf_set_name with :file command for better Vim/Neovim compatibility
  • Remove unnecessary buffer switching logic after rename
  • Store paired buffer numbers in buffer variables for reliable cleanup

Test plan

  • Test gin-blame with various file names including special characters
  • Test buffer cleanup when closing blame buffers
  • Verify compatibility with both Vim and Neovim

Summary by CodeRabbit

  • Bug Fixes
    • Improved tracking and cleanup of blame-related views so paired panes (navigation, detail, file) stay linked and are removed correctly after renames or closes.
    • Fixed issues where views could become stale or mismatched following buffer renames; state is now preserved across renames.
    • Ensured UI refresh after switching commits so the latest blame view is consistently displayed.

@coderabbitai
Copy link

coderabbitai bot commented Oct 18, 2025

Warning

Rate limit exceeded

@lambdalisue has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 18 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 96a7ec1 and 714dc46.

📒 Files selected for processing (1)
  • denops/gin/command/blame/edit.ts (9 hunks)

Walkthrough

Replaces name-based buffer tracking with per-buffer stored buffer numbers for blame nav/detail/file buffers; switches renaming from nvim_buf_set_name to noautocmd file <new-name> and updates autocmd/cleanup logic to reference stored bufnrs via getbufvar/buffer vars; adds a final redraw in switchToCommit.

Changes

Cohort / File(s) Summary
Blame buffer management refactor
denops/gin/command/blame/edit.ts
Removed storage of paired buffer names and introduced per-buffer stored buffer numbers (gin_blame_paired_bufnr_nav, gin_blame_paired_bufnr_detail, gin_blame_paired_bufnr_file, etc.). Autocmds and BufUnload handlers now fetch paired bufnrs via getbufvar. Buffer creation/rename logic stores and propagates bufnrs on nav/detail/file buffers; replaced nvim_buf_set_name with noautocmd file <new-name>/:file approach and adjusted subsequent logic to use stored bufnr references. Added redraw at end of switchToCommit. Cleanup and navigation flows updated to consistently reference stored bufnrs.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant User
  participant Cmd as blame/edit.ts
  participant NavBuf as NavBuffer
  participant DetailBuf as DetailBuffer
  participant FileBuf as FileBuffer

  Note over Cmd: Begin blame-edit flow
  User->>Cmd: open blame edit
  Cmd->>NavBuf: getbufvar(gin_blame_paired_bufnr_nav)
  Cmd->>DetailBuf: getbufvar(gin_blame_paired_bufnr_detail)
  Cmd->>FileBuf: ensure file buffer & bufnr
  alt rename required
    Cmd->>FileBuf: execute `noautocmd file <new-name>`
    FileBuf-->>Cmd: buffer updated (actual bufnr)
    Cmd->>Cmd: store bufnrs on nav/detail/file buffers
  end
  Cmd->>NavBuf: update signs/mappings using stored bufnr
  Cmd->>DetailBuf: update signs/mappings using stored bufnr
  Cmd->>Cmd: register BufUnload autocmds that read paired bufnrs via getbufvar
  Note over Cmd: switchToCommit completes
  Cmd->>Cmd: call `redraw`
  User->>Cmd: close or cleanup
  Cmd->>NavBuf: cleanup using stored bufnr
  Cmd->>DetailBuf: cleanup using stored bufnr
  Cmd->>FileBuf: cleanup using stored bufnr
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I hopped through buffers, counted each one,
Names left behind — bufnr's the fun.
A gentle noautocmd file leap,
Vars snugly stored for when I sleep.
Redraw, cleanup — tidy and done.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "fix: improve buffer cleanup and rename in gin-blame" directly aligns with the core changes described in the summary. The title accurately identifies both major refactoring areas: the buffer cleanup logic (switching from buffer names to buffer numbers and using getbufvar) and the rename logic (replacing nvim_buf_set_name with the :file command). The title is concise, specific to the gin-blame component, and clearly communicates the primary improvements without being vague or overly broad. A developer scanning the git history would understand that this PR addresses buffer management reliability and compatibility issues.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Oct 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.59%. Comparing base (353e32d) to head (714dc46).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #167   +/-   ##
=======================================
  Coverage   61.59%   61.59%           
=======================================
  Files          21       21           
  Lines        1156     1156           
  Branches      163      163           
=======================================
  Hits          712      712           
  Misses        443      443           
  Partials        1        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- Use buffer numbers instead of buffer names for cleanup autocmd
  This prevents issues when buffer names contain special characters
- Replace nvim_buf_set_name with :file command for better Vim/Neovim compatibility
- Remove unnecessary buffer switching logic after rename
- Store paired buffer numbers in buffer variables for reliable cleanup
@lambdalisue lambdalisue force-pushed the fix/blame-buffer-cleanup branch from 125f12d to 430720f Compare October 18, 2025 03:13
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 353e32d and 3fa6e25.

📒 Files selected for processing (1)
  • denops/gin/command/blame/edit.ts (7 hunks)
🧰 Additional context used
🪛 GitHub Actions: Test
denops/gin/command/blame/edit.ts

[error] 323-328: deno fmt --check failed. Found 1 not formatted file in 124 files.

🔇 Additional comments (4)
denops/gin/command/blame/edit.ts (4)

319-324: Good: store paired buffer numbers on the ginblame buffer.

This enables reliable cleanup independent of buffer names. LGTM.


355-358: Good: nav buffer stores paired bufnrs for cleanup.

Symmetric with ginblame; consistent and reliable. LGTM.


396-399: Good: detail buffer stores paired bufnrs.

Completes the triangle for robust cleanup. LGTM.


296-296: <!-- [scratchpad_start]
[task verification_formatter_issue 3/3]
Gathered git diff information and analyzed the changes.

[observations]

  • Git diff shows this PR changed the autocmd strings from multi-line template literals with bufnr() calls to single-line strings using getbufvar(str2nr(expand()...))
  • OLD code: Multi-line with bufnr('${bufnameNav.replaceAll("'", "''")}')
  • NEW code: Single-line with getbufvar(str2nr(expand('<abuf>')), 'gin_blame_paired_bufnr_nav')
  • Current file state shows lines 296, 377, 401 ARE indeed single-line strings (264-267 characters)
  • No uncommitted changes in working directory (git diff shows 0 lines)
  • biome.json is untracked in repo (possible formatter config)

[analysis]

  • The refactoring itself (template literals → getbufvar) has already been applied
  • These ARE long lines by standard metrics (>260 chars vs typical 80-120 limit)
  • Review comment claims "diffs above also improve fmt stability" but the NEW state still has long lines
  • Original concern was formatter failure due to extremely long strings
  • Without Deno formatter available, cannot verify if code passes/fails formatting checks
  • The code IS different/improved from before but may still benefit from line breaks

[pending]

  • Cannot resolve: deno fmt not available in sandbox
  • Cannot confirm: whether current state passes formatter checks
  • Cannot test: if formatter would break lines

[actions]

  • Flag as verification needed since formatter unavailable
  • Recommend manual verification by developer
  • Note that code has been changed but line lengths still exceed typical limits

[done]
Verification complete - formatter tool unavailable, cannot conclusively verify formatting status. Code has been refactored but line lengths remain long (264-267 chars).

[scratchpad_start] -->

Unable to verify formatter status—tool unavailable in sandbox.

The code has been refactored from multi-line template literals to single-line getbufvar() calls (lines 296, 377, 401), but these lines remain long (264–267 characters). The Deno formatter is unavailable to verify formatting compliance.

Please run locally:

deno fmt --check
deno fmt

Confirm the formatter passes without errors on these lines.

@lambdalisue lambdalisue force-pushed the fix/blame-buffer-cleanup branch 3 times, most recently from 2b35b92 to 6f38d9f Compare October 18, 2025 03:21
Redraw the display after switching commits (Enter key) and navigating
history (Ctrl-O/Ctrl-I) to ensure the buffer and cursor changes are
immediately visible to the user.
@lambdalisue lambdalisue force-pushed the fix/blame-buffer-cleanup branch from 6f38d9f to 714dc46 Compare October 18, 2025 03:22
@lambdalisue lambdalisue merged commit c165cfb into main Oct 18, 2025
6 checks passed
@lambdalisue lambdalisue deleted the fix/blame-buffer-cleanup branch October 18, 2025 03:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants